package com.jsgt.greekfire.ui.wallet.export

import androidx.viewpager.widget.ViewPager
import com.fhx.core.base.BaseActivity
import com.fhx.core.base.BaseFragment
import com.flyco.tablayout.listener.CustomTabEntity
import com.flyco.tablayout.listener.OnTabSelectListener
import com.jsgt.greekfire.R
import com.jsgt.greekfire.ui.mainassets.adapter.TabEntity
import com.jsgt.greekfire.ui.trading.adapter.PagerAdapter
import com.jsgt.greekfire.ui.wallet.export.fragment.KeyQRCodeFragment
import com.jsgt.greekfire.ui.wallet.export.fragment.PrivateKeyFragment
import kotlinx.android.synthetic.main.activity_private_key.*

class PrivateKeyActivity : BaseActivity() {
    private var mTabEntities =
        ArrayList<CustomTabEntity>()
    private val mFragments: MutableList<BaseFragment> = ArrayList()
    private var identityId = -1

    override fun needFitsSystemWindows(): Boolean {
        return false
    }

    override fun getLayoutId(): Int {
        return R.layout.activity_private_key
    }

    override fun main() {
        setStatusBar(R.color.transparent, false, R.color.white)
        title = getString(R.string.export_private_key)

        identityId = intent.getIntExtra("identityId", -1)
        if (identityId == -1) {
            finish()
        }

        val tabArray =
            resources.getStringArray(R.array.tab_private_key)
        val tabs = java.util.ArrayList<String>()

        mFragments.add(PrivateKeyFragment.newInstance(identityId))
        mFragments.add(KeyQRCodeFragment.newInstance(identityId))
        for (i in tabArray.indices) {
            mTabEntities.add(TabEntity(tabArray[i]))
            tabs.add(tabArray[i])
        }
        viewPager.adapter = PagerAdapter(
            supportFragmentManager,
            mFragments,
            tabs
        )

        tabLayout.setTabData(mTabEntities)
        tabLayout.setOnTabSelectListener(object : OnTabSelectListener {
            override fun onTabSelect(position: Int) {
                viewPager.currentItem = position
            }

            override fun onTabReselect(position: Int) {}
        })
        viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
            }

            override fun onPageSelected(position: Int) {
                tabLayout.currentTab = position
            }

            override fun onPageScrollStateChanged(state: Int) {}
        })
        viewPager.currentItem = 0
    }
}